
class Animal {
    protected type: string;
    constructor( type: string) {
        this.type = type ;
    }
    // 覆盖从Object原型继承的toString
    toString(): string{
        return `${this.constructor.name} { type: '${this.type}' }`;
    }
}

console.log( 'Animal原型属性: ' , Object.getOwnPropertyNames( Animal.prototype ) );

let a = new Animal( '禽类' );
console.log( a.toString() );

class Birds extends Animal {
    name: string ;
    constructor( name:string) {
        super( '禽' );
        this.name = name; 
    }
    // 覆盖从Animal继承的toString方法
    toString(): string{
        // 通过 super 调用父类中的同名方法
        let s = super.toString();
        console.log( s );
        s = s.substring( 0 , s.lastIndexOf( '}' ) );
        return s + `, name: '${this.name}'}`;
    }
}

console.log( 'Birds原型属性: ' , Object.getOwnPropertyNames( Birds.prototype ) );

let b = new Birds( '孔雀大明王' );
console.log( b.toString() );

